<?php
/**
 * Created by .
 * User: luogan
 * Date: 2022/1/17
 */

namespace app\admin\controller\v1;



use app\admin\service\AuthRoleService;
use app\admin\validate\AuthRoleValidate;
use app\interfaces\AdminInterface;
use hg\apidoc\annotation as Apidoc;
/**
 * @Apidoc\Title("角色管理")
 * @Apidoc\Group("system")
 * @Apidoc\Sort(3)
 */
class Role extends Base implements AdminInterface
{
    protected $service;

    protected $validate;

    public function __construct()
    {
        $this->service = new AuthRoleService();
        $this->validate = new AuthRoleValidate();
    }

    /**
     * @Apidoc\Title("角色列表")
     * @Apidoc\Desc("角色列表")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/role/list")
     * @Apidoc\Tag("角色")
     * @Apidoc\Param(ref="pageParam")
     * @Apidoc\Returned(ref="pageParam")
     * @Apidoc\Returned("data", type="array", ref="app\model\AuthRoleModel\getList",desc="用户列表")
     */
    public function list()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->getList($data);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("角色详情")
     * @Apidoc\Desc("角色详情")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/role/info")
     * @Apidoc\Tag("角色")
     * @Apidoc\Param("id",type="int",require=true,default="1",desc="角色id")
     * @Apidoc\Returned(ref="app\model\AuthRoleModel\getRole")
     */
    public function info()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->getInfo($data['id']);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("角色新增")
     * @Apidoc\Desc("角色新增")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/role/add")
     * @Apidoc\Tag("角色")
     * @Apidoc\Param("title",type="int",require=true,default="1",desc="角色名称")
     * @Apidoc\Param("description",type="int",require=true,default="1",desc="描述信息")
     * @Apidoc\Param("rules",type="int",require=true,default="1",desc="用户组拥有的规则id，多个规则 , 隔开")
     * @Apidoc\Param("status",type="int",require=true,default="1",desc="状态：0：正常  1：禁用")
     * @Apidoc\Returned(ref="app\model\AuthRoleModel\getRole")
     */
    public function add()
    {
        $data =request()->param();
        $this->validate->goCheck($data,__FUNCTION__);
        $result = $this->service->create($data);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("角色更新")
     * @Apidoc\Desc("角色更新")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/role/edit")
     * @Apidoc\Tag("角色")
     * @Apidoc\Param("id",type="int",require=true,default="1",desc="角色id")
     * @Apidoc\Param("title",type="int",require=true,default="1",desc="角色名称")
     * @Apidoc\Param("description",type="int",require=true,default="1",desc="描述信息")
     * @Apidoc\Param("rules",type="int",require=true,default="1",desc="用户组拥有的规则id，多个规则 , 隔开")
     * @Apidoc\Param("status",type="int",require=true,default="1",desc="状态：0：正常  1：禁用")
     */
    public function edit()
    {
        $data =request()->param();
        $this->validate->goCheck($data,__FUNCTION__);
        $result = $this->service->update($data);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("角色删除")
     * @Apidoc\Desc("角色删除")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/role/del")
     * @Apidoc\Tag("角色")
     * @Apidoc\Param("id",type="int",require=true,default="1",desc="角色id")
     */
    public function del()
    {
        $data =request()->param();
        $this->validate->goCheck($data,__FUNCTION__);
        $result = $this->service->delete($data['id']);
        return success('操作成功',$result);
    }
}
